package com.coocaa.ops.admin.v1.todotask.provider;

import com.coocaa.ops.admin.base.AbstractBizImpl;
import com.coocaa.ops.admin.v1.todotask.model.AuditTaskInfoModel;
import com.coocaa.ops.common.core.base.entity.BaseOriginTableEntity;
import com.coocaa.ops.common.core.base.model.PageResultModel;
import com.coocaa.ops.common.core.biz.homepage.entity.HomepageInfoEntity;
import com.coocaa.ops.common.tool.base.InstanceUtil;

import java.util.List;
import java.util.Map;

/**
 * @author bijiahao
 * @description
 * @date 2020/6/22 18:17
 */
public abstract class AbstractDraftTaskQueryProviderImpl<T extends BaseOriginTableEntity> implements IDraftTaskQueryProvider {

    /**
     * 获取基础业务接口实现对象
     *
     * @return
     */
    abstract public AbstractBizImpl getAbstractBizImpl();

    @Override
    public PageResultModel queryDraftPageResult(AuditTaskInfoModel model, Integer userId) {
        Map<String, Object> params = this.convertQueryParams(model, userId);
        Integer total = getAbstractBizImpl().getMapper().selectCountPage(params);
        List<BaseOriginTableEntity> data = InstanceUtil.newArrayList();
        if (total > 0) {
            data = getAbstractBizImpl().getMapper().queryCommonPageList(params);
        }
        return PageResultModel.getPageResultModel(total, data);
    }


    @Override
    public Integer queryDraftCount(Map params) {
        Integer total = getAbstractBizImpl().getMapper().selectCountPage(params);
        return total;
    }

    /**
     * 获取查询参数
     *
     * @param model
     * @param userId
     * @return
     */
    abstract protected Map<String, Object> convertQueryParams(AuditTaskInfoModel model, Integer userId);
}
